package com.yoomiito.app.widget.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.yoomiito.app.R;
import com.yoomiito.app.listener.OnViewClickListener;
import com.yoomiito.app.model.bean.BannerAndIconInfo;
import com.yoomiito.app.model.home.FreeBuyActInfo;
import com.yoomiito.app.model.home.SystemDialogInfo;
import com.yoomiito.app.utils.ImageLoader;

/**
 * 后台配置弹窗
 */
public class SystemDialog extends BaseDialog implements View.OnClickListener {
    private OnViewClickListener mOnViewClickListener;
    private OnViewClickListener mGoClickListener;

    private BannerAndIconInfo mSystemDialogInfo;
    private ImageView iv;
    public ImageView btnGo;
    private int btnGoResId = 0;
    public SystemDialog(@NonNull Context context) {
        this(context,0);
    }

    public SystemDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_system_config,null,false);
        view.findViewById(R.id.cancel).setOnClickListener(this);
        iv = view.findViewById(R.id.bg_now_buy);
        btnGo = view.findViewById(R.id.btnGo);
        btnGo.setOnClickListener(this);
        if (btnGoResId!=0){
            btnGo.setImageResource(btnGoResId);
            btnGo.setVisibility(View.VISIBLE);
        }
        iv.setOnClickListener(this);
        if (mSystemDialogInfo!=null){
            ImageLoader.getInstance().into(mContext,mSystemDialogInfo.getImage_url(),iv);
        }
        setCanceledOnTouchOutside(true);
        setmHeightPercent(1);
        setWidthPercent(1);
        return view;
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.cancel:
                dismiss();
                break;
            case R.id.bg_now_buy:
                if (mOnViewClickListener!=null){
                    mOnViewClickListener.onClick(v);
                }
                break;
            case R.id.btnGo:
                if (mGoClickListener!=null){
                    mGoClickListener.onClick(v);
                }
                break;
        }
    }

    public void setOnViewClickListener(OnViewClickListener onViewClickListener) {
        mOnViewClickListener = onViewClickListener;
    }

    public void setmGoClickListener(OnViewClickListener mGoClickListener) {
        this.mGoClickListener = mGoClickListener;
    }

    public void setSystemDialogInfo(BannerAndIconInfo freeBuyActInfo) {
        mSystemDialogInfo = freeBuyActInfo;
        if (iv!=null){
            ImageLoader.getInstance().into(mContext,mSystemDialogInfo.getBg_image_url(),iv);
        }
    }

    public void setBtnGoResId(int btnGoResId) {
        this.btnGoResId = btnGoResId;
        if (btnGo!=null){
            btnGo.setImageResource(btnGoResId);
            btnGo.setVisibility(View.VISIBLE);
        }
    }
}
